package com.example.androiddemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

public class MainActivity2 extends AppCompatActivity {

    private TextView textView;
    private List<Integer> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Bundle extras = getIntent().getExtras();
        if (extras != null){
            data = extras.getIntegerArrayList("data");
        }
        initView();
    }

    private void initView() {
        textView = findViewById(R.id.data);
        String res = "";
        for (int i = 0; i < data.size(); i++) {
            res += data.get(i) + "\n";
        }
        copyTextToClipboard(res);
    }

    public void copyTextToClipboard(String text) {
        ClipboardManager clipboard = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("label", text));
        Toast.makeText(this, "文本已复制到剪贴板", Toast.LENGTH_SHORT).show();
    }
}